import {Message} from 'element-ui'
import {shopcartGoods} from '../../api/goods'
var storage=window.localStorage

const goods = {
    state:{
        productList:[]
    },
    mutations:{
        SET_PRODUCT(state,productList){
            state.productList = productList
        },
        ADD_PRODUCT(state,product){
            state.productList.push(product)
        }
    },
    actions: {
        get_product(context){
            return new Promise((resolve,reject)=>{
                shopcartGoods('').then(res=>{
                    //console.log(res.data.productList)
                    storage.setItem('shopcart',JSON.stringify(res.data.productList))
                    context.commit('SET_PRODUCT',res.data.productList)
                    resolve()
                }).catch(error => {
                    reject(error)
                })
            })
        }
    }
}


export default goods


